import axios from 'axios';
import qs from 'qs';

const apiClient = axios.create({
    baseURL: 'http://localhost:8080/api',
    headers: {
        'Content-Type': 'application/json',
    },
});

export default {
    registerUser(user) {
        return apiClient.post('/register', user);
    },
    loginUser(user) {
        return apiClient.post('/login', user);
    },
    getUserById(id) {
        return apiClient.get(`/user/${id}`);
    },
    updateUser(user) {
        return apiClient.put('/user', user);
    },
    recordHealthData(healthData) {
        return apiClient.post('/healthdata', healthData);
    },
    getHealthData(userId, date) {
        const params = { userId, date };
        return apiClient.get(`/healthdata?${qs.stringify(params)}`);
    },
    getHealthDataByUserId(userId) {
        return apiClient.get(`/healthdata/${userId}`);
    },
    createRecommendations(recommendations) {
        return apiClient.post('/recommendations', recommendations);
    },
    getRecommendations(userId, date) {
        const params = { userId, date };
        return apiClient.get(`/recommendations?${qs.stringify(params)}`);
    },
    createRiskPrediction(riskPredictions) {
        return apiClient.post('/riskpredictions', riskPredictions);
    },
    getRiskPrediction(userId, date) {
        const params = { userId, date };
        return apiClient.get(`/riskpredictions?${qs.stringify(params)}`);
    },
    createVisualization(visualizations) {
        return apiClient.post('/visualizations', visualizations);
    },
    getVisualization(userId, date) {
        const params = { userId, date };
        return apiClient.get(`/visualizations?${qs.stringify(params)}`);
    },
    getVisualizationsByUserId(userId) {
        return apiClient.get(`/visualizations/${userId}`);
    },
    createSocialFeature(socialFeatures) {
        return apiClient.post('/socialfeatures', socialFeatures);
    },
    getSocialFeaturesByUserId(userId) {
        const params = { userId };
        return apiClient.get(`/socialfeatures?${qs.stringify(params)}`);
    },
    getSocialFeaturesByUserIdAndFriendId(userId, friendId) {
        return apiClient.get(`/socialfeatures/${userId}/${friendId}`);
    },
};
